package com.ecsolutions.service.asset;

import com.ecsolutions.dao.asset.DepositDao;
import com.ecsolutions.entity.asset.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/5/10.
 */
@Service
public class DepositServiceImpl implements DepositService {
    private DepositDao depositDao;

    @Autowired
    public DepositServiceImpl(DepositDao depositDao) {
        this.depositDao = depositDao;
    }

    @Override
    public List<DepositCurrencyEntity> getBalanceOfEachCurrency(String customer_code) {
        return depositDao.getBalanceOfEachCurrency(customer_code);
    }

    @Override
    public List<DepositCurrencyEntity> getBalanceOfEachAccType(String customer_code, String currency) {
        return depositDao.getBalanceOfEachAccType(customer_code, currency);
    }

    @Override
    public List<DepositCurrencyEntity> getAssetList(String customer_code) {
        List<DepositCurrencyEntity> depositEntities = this.depositDao.getCurrencies(customer_code);
        String currency = null;
        List<DepositTypeEntity> depositTypeEntities = null;
        for (DepositCurrencyEntity depositCurrencyEntity :depositEntities
             ) {
            currency = depositCurrencyEntity.getCurrency();
            depositTypeEntities = this.depositDao.getDepositTypes(customer_code, currency);
            depositCurrencyEntity.setDepositType(depositTypeEntities);
        }
        return depositEntities;
    }

    @Override
    public DepositEntity getAssets(String customer_code) {
        DepositEntity depositEntity = new DepositEntity();
        List<DepositCurrencyEntity> depositCurrencyEntities = this.depositDao.getCurrencies(customer_code);
        List<DepositNatureEntity> depositNatureEntities = this.depositDao.getNaturePercent(customer_code);
        String nature = null;
        List<DepositCurrencyEntity> depositCurrencyEntities1 = null;
        for (DepositNatureEntity depositNatureEntity : depositNatureEntities) {
            nature = depositNatureEntity.getAccount_nature();
            depositCurrencyEntities1 = this.depositDao.getNatureCurrencies(customer_code, nature);
            depositNatureEntity.setDepositCurrencies(depositCurrencyEntities1);
        }
//        List<DepositPercentEntity> depositPercentEntities = this.depositDao.getPercent(customer_code);
        depositEntity.setDepositCurrency(depositCurrencyEntities);
        depositEntity.setDepositNature(depositNatureEntities);
//        depositEntity.setDepositPercent(depositPercentEntities);
        return depositEntity;
    }

    @Override
    public List<DepositTypeEntity> getNatureAccounts(String customer_code, String nature) {
        List<DepositTypeEntity> depositTypeEntities = this.depositDao.getNatureAccounts(customer_code, nature);
        String account = "";
        List<DepositCurrencyEntity> depositCurrencyEntities = null;
        for (DepositTypeEntity depositTypeEntity : depositTypeEntities) {
            account = depositTypeEntity.getDp_account_no();
            depositCurrencyEntities = this.depositDao.getAccountCurrencies(customer_code, nature, account);
            depositTypeEntity.setCurrencies(depositCurrencyEntities);
        }


        return depositTypeEntities;
    }
}
